//
//  JDWechatManager.swift
//  DragonWallet
//
//  Created by volantPig on 2025/5/8.
//

import UIKit
import SwiftyJSON

class JDWechatManager: NSObject {

    static let `default` = JDWechatManager()
    
    func initSDK() {
//        wx1062cb5472f1003b wx04e04d62442fb578
        WXApi.registerApp("wx1062cb5472f1003b", universalLink: "https://dev.xiaolongbaobao.com/api/")
    }
    
    func  checkAction() {
        //调用自检函数

        WXApi.checkUniversalLinkReady { step, result in
            print("%d, %u, %@, %@",(step), result.success, result.errorInfo, result.suggestion)
        }
    }
     
    /// 微信认证
    static func sendAuthRequest() {
        let request = SendAuthReq()
        request.scope = "snsapi_userinfo"
        request.state = "xiaolongbao"
        WXApi.send(request)
//        WXApi.sendAuthReq(<#T##req: SendAuthReq##SendAuthReq#>, viewController: <#T##UIViewController#>, delegate: <#T##(any WXApiDelegate)?#>, completion: <#T##((Bool) -> Void)?##((Bool) -> Void)?##(Bool) -> Void#>)
    }
    
    /// 微信支付
    func wechatPayRequest(_ payModel: JDWechatPayModel) {

//        https://pay.weixin.qq.com/doc/global/v3/zh/4013014230   有示例代码
//        https://pay.weixin.qq.com/doc/v2/merchant/4011937148   有参数示意
        
        let payRequest = PayReq()
        
        print("查看所有参数")
        
//        payRequest.openID = payModel.appid ?? ""
        payRequest.partnerId = payModel.partnerId ?? ""
        payRequest.prepayId = payModel.prepayId ?? ""
        payRequest.package = payModel.packageVal ?? "Sign=WXPay"
        payRequest.nonceStr = payModel.nonceStr ?? "jd"
        payRequest.timeStamp = JSON(payModel.timestamp  as Any).uInt32Value // (JSON(JDTools.currentTimeStamp() as Any).uInt32Value)//"时间长，坐拥同上"
        payRequest.sign = payModel.sign ?? "jd"
        WXApi.send(payRequest)
        
 
    }
    
    
}
